package ru.spies.pages;

import ru.spies.forms.DBFunctionalForm;
import ru.spies.help.DataTableCreator;
import ru.spies.profileClasses.UserInfo;

public class ShowUsersPage extends AbstractPage {

	private static ShowUsersPage statThis;
	
	private static final String PAGE_NAME="Отображение результатов";
	
	private static final String TABLE_NAME="showUsers";	
	private static String COLUMNS[]={"userName","role"};

	private ShowUsersPage() {
		
	}
	
	public static ShowUsersPage getInstance(){
		if (statThis==null){
			statThis = new ShowUsersPage();
		}
		return statThis;
	}

	@Override
	public String getThisPage() {
		return getPage(PAGE_NAME, DBFunctionalForm.getInstance().createShowUserForm(), getHeadContent());
	}
	
	private String getHeadContent(){
		return DataTableCreator.getInstance(TABLE_NAME).getJSSource(getCols());
	}
	
	private String[] getCols(){
		String retVal[];
		if (UserInfo.getInstance().getPrivileges().canDoNormalShow()){
			retVal = new String[COLUMNS.length+1];
			retVal[COLUMNS.length]="agentName";
		} else {
			retVal = new String[COLUMNS.length];
		}
		for (int i = 0; i < COLUMNS.length; i++) {
			retVal[i]=COLUMNS[i];
		}
		return retVal;
	}

}
